#include "mytext.h"

#include <iostream>
#include <string>
using namespace std;

// TTF_Init() must be called before using this function.
// Remember to call TTF_Quit() when done.

MyText::MyText(int size, char* filename)
{
    if(!TTF_WasInit() )
         TTF_Init();

    font = TTF_OpenFont(filename, size);
}

void MyText::setup(int size, char* filename)
{
    font = TTF_OpenFont(filename, size);
}

void MyText::draw(int number, int x, int y, int fR, int fG, int fB, SDL_Surface* screen)
{
    char buffer[100];
    int myInteger = number;
    sprintf(buffer, "%i", myInteger);

    SDL_Color foregroundColor = { fR, fG, fB };
    //SDL_Color backgroundColor = { 0, 0, 255 };

    SDL_Surface* textSurface = TTF_RenderText_Blended(font,buffer, foregroundColor);
    //SDL_Surface* textSurface = TTF_RenderText_Shaded(font,buffer, foregroundColor, backgroundColor);
       // Pass zero for width and height to draw the whole surface
    SDL_Rect textLocation = { x, y, 0, 0 };
   // SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));

    SDL_BlitSurface(textSurface, NULL, screen, &textLocation);
    SDL_FreeSurface(textSurface);
}

void MyText::draw(char* string, int x, int y,
                  int fR, int fG, int fB, SDL_Surface* screen) //  int bR, int bG, int bB)
{
    SDL_Color foregroundColor = { fR, fG, fB };
   //SDL_Color backgroundColor = { bR, bG, bB };

   SDL_Surface* textSurface2 = TTF_RenderText_Blended(font, string, foregroundColor);
   // to render solid
   //SDL_Surface* textSurface = TTF_RenderText_Shaded(font,buffer, foregroundColor, backgroundColor);

   SDL_Rect textLocation = { x, y, 0, 0 };
  // SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));

   SDL_BlitSurface(textSurface2, NULL, screen, &textLocation);

   SDL_FreeSurface(textSurface2);
}

MyText::~MyText()
{
    TTF_CloseFont(font);
}
